package com.industrial.white.service.impl;

/*import com.enterprise.common.core.domain.entity.SysUser;
import com.enterprise.common.utils.SecurityUtils;
import com.enterprise.system.domain.EmEnterpriseInformationCollection;
import com.enterprise.system.domain.EmTimeRole;
import com.enterprise.system.domain.EmUserEnter;
import com.enterprise.system.domain.vo.TimeRoleVo;
import com.enterprise.system.mapper.EmEnterpriseInformationCollectionMapper;
import com.enterprise.system.mapper.EmTimeRoleMapper;
import com.enterprise.system.mapper.EmUserEnterMapper;
import com.enterprise.system.mapper.SysUserRoleMapper;
import com.enterprise.system.service.IEmEnterpriseInformationCollectionService;
import com.enterprise.system.service.IEmTimeRoleService;*/
import com.industrial.common.security.utils.SecurityUtils;
import com.industrial.system.api.domain.SysUser;
import com.industrial.system.api.domain.EmEnterpriseInformationCollection;
import com.industrial.white.domain.EmTimeRole;
import com.industrial.white.mapper.EmEnterpriseInformationCollectionMapper;
import com.industrial.white.mapper.EmTimeRoleMapper;
import com.industrial.white.service.IEmTimeRoleService;
import com.industrial.white.vo.TimeRoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 时间限制Service业务层处理
 * 
 * @author ZHOU_S
 * @date 2023-08-19
 */
@Service
public class EmTimeRoleServiceImpl implements IEmTimeRoleService
{
    @Autowired
    private EmTimeRoleMapper emTimeRoleMapper;
    @Autowired
    private EmEnterpriseInformationCollectionMapper emEnterpriseInformationCollectionMapper;


    @Override
    public List<TimeRoleVo> getTimeRole(EmTimeRole emTimeRole) {
        List<TimeRoleVo> list=new ArrayList<>();
        SysUser user= SecurityUtils.getLoginUser().getSysUser();
        String  role= SecurityUtils.getLoginUser().getSysUser().getRoles().get(0).getRoleKey();
        EmEnterpriseInformationCollection emEnterpriseInformationCollection=
                emEnterpriseInformationCollectionMapper.getEnterDataInfo(user.getUserName());
            if(emEnterpriseInformationCollection!=null){
                if(emEnterpriseInformationCollection.getAdCheckPState()!=null){
                    if("q_01_001".contains(role)||"white".contains(role)){
                        Date loginTime=new Date();
                        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String  loginTimes =sdf.format(loginTime);
                        List<EmTimeRole> emTimeRoleList=emTimeRoleMapper.selectEmTimeRoleList(emTimeRole);
                        for (EmTimeRole emr:emTimeRoleList) {
                            TimeRoleVo tv=new TimeRoleVo();
                            tv.setMenuId(emr.getMenuId());
                            tv.setMenuName(emr.getMenuName());
                            int start =  loginTimes.compareTo(sdf.format(emr.getBaseStartTime()));
                            int end = loginTimes.compareTo(sdf.format(emr.getBaseEndTime()));
                            if(start>0&&end<0){
                                tv.setIsExpire("1");
                            }else if(start<0&&end<0){
                                tv.setIsExpire("0");
                            }else if(end>0){
                                tv.setIsExpire("2");
                            }
                            list.add(tv);
                        }
                    }
                }
            }

        return  list;
    }

    /**
     * 查询时间限制
     * @param baseId 时间限制主键
     * @return 时间限制
     */
    @Override
    public EmTimeRole selectEmTimeRoleByBaseId(String baseId)
    {
        return emTimeRoleMapper.selectEmTimeRoleByBaseId(baseId);
    }

    /**
     * 查询时间限制列表
     * @param emTimeRole 时间限制
     * @return 时间限制
     */
    @Override
    public List<EmTimeRole> selectEmTimeRoleList(EmTimeRole emTimeRole)
    {
        List<EmTimeRole> emTimeRoles = emTimeRoleMapper.selectEmTimeRoleList(emTimeRole);
        
        return emTimeRoles;
    }

    /**
     * 新增时间限制
     * @param emTimeRole 时间限制
     * @return 结果
     */
    @Override
    public int insertEmTimeRole(EmTimeRole emTimeRole)
    {
        return emTimeRoleMapper.insertEmTimeRole(emTimeRole);
    }

    /**
     * 修改时间限制
     * 
     * @param emTimeRole 时间限制
     * @return 结果
     */
    @Override
    public int updateEmTimeRole(EmTimeRole emTimeRole)
    {
        return emTimeRoleMapper.updateEmTimeRole(emTimeRole);
    }

    /**
     * 批量删除时间限制
     * 
     * @param baseIds 需要删除的时间限制主键
     * @return 结果
     */
    @Override
    public int deleteEmTimeRoleByBaseIds(String[] baseIds)
    {
        return emTimeRoleMapper.deleteEmTimeRoleByBaseIds(baseIds);
    }

    /**
     * 删除时间限制信息
     * 
     * @param baseId 时间限制主键
     * @return 结果
     */
    @Override
    public int deleteEmTimeRoleByBaseId(String baseId)
    {
        return emTimeRoleMapper.deleteEmTimeRoleByBaseId(baseId);
    }
}
